package com.br.ufrn.laut.braipetro.app;

import android.app.Activity;
import android.os.Bundle;
import android.widget.Button;
import android.view.View;
import android.widget.EditText;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import com.br.ufrn.laut.braipetro.app.R;

/**
 * Created by andreqbs on 18/04/2014.
 */
public class ConfiguracaoActivity extends Activity {

    private Button btnSalvar;
    private EditText edtServidor = null;
    private EditText edtPorta = null;
    private Context _context = null;

    public static String servidor = "http://";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.config_activity);

        btnSalvar = (Button) findViewById(R.id.btnSalvar);
        edtServidor = (EditText) findViewById(R.id.edtServidor);
        edtPorta = (EditText) findViewById(R.id.edtPorta);

        //edtServidor.setText(servidor);

        edtServidor.setText("http://10.13.100.");
        edtPorta.setText("8080");
    }

    public ConfiguracaoActivity() {

    }

    public ConfiguracaoActivity(Context context){
        this._context = context;
    }

    public boolean conectado(){
        ConnectivityManager connectivity = (ConnectivityManager) _context.getSystemService(Context.CONNECTIVITY_SERVICE);
        if (connectivity != null)
        {
            NetworkInfo[] info = connectivity.getAllNetworkInfo();
            if (info != null)
                for (int i = 0; i < info.length; i++)
                    if (info[i].getState() == NetworkInfo.State.CONNECTED)
                    {
                        return true;
                    }
        }
        return false;
    }

    public void salvar(View view) {
        servidor = edtServidor.getText() + ":" + edtPorta.getText();
        finish();
    }
}
